package com.qinggeng.framework.config.mq.impl;
import com.alibaba.fastjson.JSONObject;
import com.qinggeng.common.exception.CustomException;
import com.qinggeng.framework.config.mq.dto.MessageAccountDTO;
import com.qinggeng.framework.config.mq.handle.MessageHandle;
import com.qinggeng.project.system.service.IUserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class AccountSubMoneyHandleImpl implements MessageHandle {
    @Autowired
    IUserAccountService userAccountService;
    @Override
    public void handle(String msg) {
        System.out.println("解析handle "+msg);
        try {
            MessageAccountDTO messageAccountDTO=JSONObject.parseObject(msg,MessageAccountDTO.class);
            Long messageId=messageAccountDTO.getMessageId();
            Long userId=messageAccountDTO.getUserId();
            String monery=messageAccountDTO.getMoney();
            userAccountService.subUserAccountMoney(messageId,userId,monery);
        }catch (Exception e){
            throw  new CustomException("錯誤"+e.getMessage());

        }
    }

}
